import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//引入自动导入的插件
import AutoImport from 'unplugin-auto-import/vite'
//引入路径模块
import path from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
      'vue': 'vue/dist/vue.esm-bundler.js'
    }
  },
  server: {
    proxy: {
      //设置代理请求 当代理商识别你的请求如果前缀是 /api的话 就会自动转移
      '/shop': {
        target: 'http://tvue.teakun.top/shop',    //上线
        // target: 'http://www.fastpro.com/shop',   //本地
        changeOrigin: true,  //跨域
        //替换掉api前缀 防止多个api地址
        rewrite: (path) => path.replace(/^\/shop/, ''),
      },
      '/api': {
        target: 'http://localhost:80/php/apis', // 替换为目标服务器地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '') // 移除/api前缀
      }
    },
  },
  plugins: [
    vue(),
    AutoImport({
      imports: [
        'vue', 'vue-router',
        {
          '@/api/index': [
            ['default', 'Api'], // 引入全局默认导出API请求
          ],
          'vant': [
            'showSuccessToast', 'showFailToast', 'showConfirmDialog'
          ]
        }
    ]
    })],
})
